package com.fivestar.pmanager.service;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fivestar.pmanager.core.base.BaseCommonParameterBean;
import com.fivestar.pmanager.core.exception.DMLNoRecordEffectedException;
import com.fivestar.pmanager.core.service.BaseServiceImpl;
import com.fivestar.pmanager.dao.mapper.SysRoleOperationRelaMapper;
import com.fivestar.pmanager.model.SysRoleOperationRelaBean;

 /**
 * 用户角色操作关系表
 * SysRoleOperationRelaService
 * @author 
 */
@Service("sysRoleOperationRelaService")
public class SysRoleOperationRelaService extends BaseServiceImpl<SysRoleOperationRelaBean>
{
	private final static Logger log = Logger.getLogger(SysRoleOperationRelaService.class);
	@Autowired
    private SysRoleOperationRelaMapper mapper;


    @Override
    public int insert(SysRoleOperationRelaBean SysRoleOperationRelaBean, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
    	SysRoleOperationRelaBean.initBeforeCreate(commonParam.getActorId());
        int result;
        if ((result = mapper.insert(SysRoleOperationRelaBean)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }


    @Override
    public int delete(SysRoleOperationRelaBean smRoleOperationRela, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
        smRoleOperationRela.initBeforeUpdate(commonParam.getActorId());
        int result;
        if ((result = mapper.delete(smRoleOperationRela)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }

    @Override
    public int deletePhysics(SysRoleOperationRelaBean smRoleOperationRela, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException {
        int result;
        if ((result = mapper.deletePhysics(smRoleOperationRela)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }


    @Override
    public int update(SysRoleOperationRelaBean smRoleOperationRela, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
        smRoleOperationRela.initBeforeUpdate(commonParam.getActorId());
        int result;
        if ((result = mapper.update(smRoleOperationRela)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }
    
    
    @Override
    public int updateBySelective(SysRoleOperationRelaBean smRoleOperationRela, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
        smRoleOperationRela.initBeforeUpdate(commonParam.getActorId());
        int result;
        if ((result = mapper.updateBySelective(smRoleOperationRela)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }


    @Override
    public List<SysRoleOperationRelaBean> getList(SysRoleOperationRelaBean smRoleOperationRela)
    {
        return mapper.getList(smRoleOperationRela);
    }


    @Override
    public SysRoleOperationRelaBean getSingleById(Integer arg0)
    {
        return mapper.getSingleById(arg0);
    }


    @Override
    public int getCountOfPage(SysRoleOperationRelaBean smRoleOperationRela)
    {
        return mapper.getCountOfPage(smRoleOperationRela);
    }


    @Override
    public List<SysRoleOperationRelaBean> getListOfPage(SysRoleOperationRelaBean smRoleOperationRela)
    {
        return mapper.getListOfPage(smRoleOperationRela);
    }


	@Override
    public int getCount(SysRoleOperationRelaBean smRoleOperationRela)
    {
        return mapper.getCount(smRoleOperationRela);
    }


    @Override
    public void save(SysRoleOperationRelaBean smRoleOperationRela, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
        if(smRoleOperationRela.getRowId() == null)
        {
            insert(smRoleOperationRela, commonParam);
        }
        else
        {
            updateBySelective(smRoleOperationRela, commonParam);
        }
    }


    @Override
    public SysRoleOperationRelaBean getSingle(SysRoleOperationRelaBean smRoleOperationRela)
    {
        return mapper.getSingle(smRoleOperationRela);
    }

    /**
     * 获取角色和url的关系
     *
     * @return
     */
    public List<Map<String,Object>> findAllRoleAndOperation()
    {
        return mapper.findAllRoleAndOperation();
    }
    
    /**
     * 获取公共权限
     *
     * @return
     */
    public List<Map<String,Object>> findCommRoleAndOperation()
    {
        return mapper.findCommRoleAndOperation();
    }
    
    /**
     * 删除角色操作对应关系
     * @param SysRoleOperationRelaBean
     * @return
     */
    public int deleteBySelective(SysRoleOperationRelaBean sysRoleOperationRelaBean){
    	return mapper.deleteBySelective(sysRoleOperationRelaBean);
    }
}
